<!-- HTML header for doxygen 1.8.6-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.13"/>
<title>OpenCV: Detecting colorcheckers using neural network</title>
<link href="../../opencv.ico" rel="shortcut icon" type="image/x-icon" />
<link href="../../tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../jquery.js"></script>
<script type="text/javascript" src="../../dynsections.js"></script>
<script type="text/javascript" src="../../tutorial-utils.js"></script>
<link href="../../search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../search/searchdata.js"></script>
<script type="text/javascript" src="../../search/search.js"></script>
<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
    extensions: ["tex2jax.js", "TeX/AMSmath.js", "TeX/AMSsymbols.js"],
    jax: ["input/TeX","output/HTML-CSS"],
});
//<![CDATA[
MathJax.Hub.Config(
{
  TeX: {
      Macros: {
          matTT: [ "\\[ \\left|\\begin{array}{ccc} #1 & #2 & #3\\\\ #4 & #5 & #6\\\\ #7 & #8 & #9 \\end{array}\\right| \\]", 9],
          fork: ["\\left\\{ \\begin{array}{l l} #1 & \\mbox{#2}\\\\ #3 & \\mbox{#4}\\\\ \\end{array} \\right.", 4],
          forkthree: ["\\left\\{ \\begin{array}{l l} #1 & \\mbox{#2}\\\\ #3 & \\mbox{#4}\\\\ #5 & \\mbox{#6}\\\\ \\end{array} \\right.", 6],
          forkfour: ["\\left\\{ \\begin{array}{l l} #1 & \\mbox{#2}\\\\ #3 & \\mbox{#4}\\\\ #5 & \\mbox{#6}\\\\ #7 & \\mbox{#8}\\\\ \\end{array} \\right.", 8],
          vecthree: ["\\begin{bmatrix} #1\\\\ #2\\\\ #3 \\end{bmatrix}", 3],
          vecthreethree: ["\\begin{bmatrix} #1 & #2 & #3\\\\ #4 & #5 & #6\\\\ #7 & #8 & #9 \\end{bmatrix}", 9],
          cameramatrix: ["#1 = \\begin{bmatrix} f_x & 0 & c_x\\\\ 0 & f_y & c_y\\\\ 0 & 0 & 1 \\end{bmatrix}", 1],
          distcoeffs: ["(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6 [, s_1, s_2, s_3, s_4[, \\tau_x, \\tau_y]]]]) \\text{ of 4, 5, 8, 12 or 14 elements}"],
          distcoeffsfisheye: ["(k_1, k_2, k_3, k_4)"],
          hdotsfor: ["\\dots", 1],
          mathbbm: ["\\mathbb{#1}", 1],
          bordermatrix: ["\\matrix{#1}", 1]
      }
  }
}
);
//]]>
</script><script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js"></script>
<link href="../../doxygen.css" rel="stylesheet" type="text/css" />
<link href="../../stylesheet.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<!--#include virtual="/google-search.html"-->
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><img alt="Logo" src="../../opencv-logo-small.png"/></td>
  <td style="padding-left: 0.5em;">
   <div id="projectname">OpenCV
   &#160;<span id="projectnumber">4.5.2</span>
   </div>
   <div id="projectbrief">Open Source Computer Vision</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.13 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "../../search",false,'Search');
</script>
<script type="text/javascript" src="../../menudata.js"></script>
<script type="text/javascript" src="../../menu.js"></script>
<script type="text/javascript">
$(function() {
  initMenu('../../',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
</script>
<div id="main-nav"></div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="../../d3/d81/tutorial_contrib_root.html">Tutorials for contrib modules</a></li><li class="navelem"><a class="el" href="../../d0/d81/tutorial_table_of_content_mcc.html">ColorChecker Detection</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="headertitle">
<div class="title">Detecting colorcheckers using neural network </div>  </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><p>In this tutorial you will learn how to use the neural network to boost up the accuracy of the chart detection algorithm.</p>
<h2>Building </h2>
<p>When building OpenCV, run the following command to build all the contrib module:</p>
<div class="fragment"><div class="line">cmake -D OPENCV_EXTRA_MODULES_PATH=&lt;opencv_contrib&gt;/modules/</div></div><!-- fragment --><p>Or only build the mcc module:</p>
<div class="fragment"><div class="line">cmake -D OPENCV_EXTRA_MODULES_PATH=&lt;opencv_contrib&gt;/modules/mcc</div></div><!-- fragment --><p>Or make sure you check the mcc module in the GUI version of CMake: cmake-gui.</p>
<h2>Source Code of the sample </h2>
<p>You can run the sample code by doing</p>
<div class="fragment"><div class="line">&lt;path_of_your_opencv_build_directory&gt;/bin/example_mcc_chart_detection_with_network -t=&lt;type_of_chart&gt; -m=&lt;path_to_neural_network&gt; -pb=&lt;path_to_models_pbtxt&gt; -v=&lt;optional_path_to_video_if_not_provided_webcam_will_be_used.mp4&gt; --ci=&lt;optional_camera_id_needed_only_if_video_not_provided&gt; --nc=&lt;optional_maximum_number_of_charts_in_image&gt; --use_gpu &lt;optional_should_gpu_be_used&gt;</div><div class="line"></div><div class="line">``&#39;</div><div class="line"></div><div class="line">* -t=#  is the chart type where 0 (Standard), 1 (DigitalSG), 2 (Vinyl)</div><div class="line">* --ci=#  is the camera ID where 0 (default is the main camera), 1 (secondary camera) etc</div><div class="line">* --nc=#  By default its values is 1 which means only the best chart will be detected</div><div class="line"></div><div class="line">Example:</div></div><!-- fragment --><p> Simple run on CPU (GPU wont be used) /home/opencv/build/bin/example_mcc_chart_detection_with_network -t=0 -m=/home/model.pb &ndash;pb=/home/model.pbtxt -v=mcc24.mp4 </p><div class="fragment"></div><!-- fragment --><p> To run on GPU /home/opencv/build/bin/example_mcc_chart_detection_with_network -t=0 -m=/home/model.pb &ndash;pb=/home/model.pbtxt -v=mcc24.mp4 &ndash;use_gpu</p>
<p>To run on GPU and detect the best 5 charts (Detections can be less than 5 but not more than 5) /home/opencv/build/bin/example_mcc_chart_detection_with_network -t=0 -m=/home/model.pb &ndash;pb=/home/model.pbtxt -v=mcc24.mp4 &ndash;use_gpu &ndash;nc=5 ```</p>
<div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno">    1</span>&#160;<span class="preprocessor">#include &lt;<a class="code" href="../../d0/d9c/core_2include_2opencv2_2core_8hpp.html">opencv2/core.hpp</a>&gt;</span></div><div class="line"><a name="l00002"></a><span class="lineno">    2</span>&#160;</div><div class="line"><a name="l00003"></a><span class="lineno">    3</span>&#160;<span class="preprocessor">#include &lt;<a class="code" href="../../d4/dd5/highgui_8hpp.html">opencv2/highgui.hpp</a>&gt;</span></div><div class="line"><a name="l00004"></a><span class="lineno">    4</span>&#160;<span class="preprocessor">#include &lt;<a class="code" href="../../df/d35/mcc_8hpp.html">opencv2/mcc.hpp</a>&gt;</span></div><div class="line"><a name="l00005"></a><span class="lineno">    5</span>&#160;<span class="preprocessor">#include &lt;<a class="code" href="../../d9/d8c/dnn_8hpp.html">opencv2/dnn.hpp</a>&gt;</span></div><div class="line"><a name="l00006"></a><span class="lineno">    6</span>&#160;<span class="preprocessor">#include &lt;iostream&gt;</span></div><div class="line"><a name="l00007"></a><span class="lineno">    7</span>&#160;</div><div class="line"><a name="l00008"></a><span class="lineno">    8</span>&#160;<span class="keyword">using namespace </span>std;</div><div class="line"><a name="l00009"></a><span class="lineno">    9</span>&#160;<span class="keyword">using namespace </span><a class="code" href="../../d2/d75/namespacecv.html">cv</a>;</div><div class="line"><a name="l00010"></a><span class="lineno">   10</span>&#160;<span class="keyword">using namespace </span>mcc;</div><div class="line"><a name="l00011"></a><span class="lineno">   11</span>&#160;</div><div class="line"><a name="l00012"></a><span class="lineno">   12</span>&#160;<span class="keyword">const</span> <span class="keywordtype">char</span> *about = <span class="stringliteral">&quot;Basic chart detection using neural network&quot;</span>;</div><div class="line"><a name="l00013"></a><span class="lineno">   13</span>&#160;<span class="keyword">const</span> <span class="keywordtype">char</span> *keys = {</div><div class="line"><a name="l00014"></a><span class="lineno">   14</span>&#160;    <span class="stringliteral">&quot;{ help h usage ? |    | show this message }&quot;</span></div><div class="line"><a name="l00015"></a><span class="lineno">   15</span>&#160;    <span class="stringliteral">&quot;{t       | 0   | chartType: 0-Standard, 1-DigitalSG, 2-Vinyl, default:0}&quot;</span></div><div class="line"><a name="l00016"></a><span class="lineno">   16</span>&#160;    <span class="stringliteral">&quot;{m       |     | File path of model, if you don&#39;t have the model you can \</span></div><div class="line"><a name="l00017"></a><span class="lineno">   17</span>&#160;<span class="stringliteral">                      find the link in the documentation}&quot;</span></div><div class="line"><a name="l00018"></a><span class="lineno">   18</span>&#160;    <span class="stringliteral">&quot;{pb      |     | File path of pbtxt file, available along with with the model \</span></div><div class="line"><a name="l00019"></a><span class="lineno">   19</span>&#160;<span class="stringliteral">                      file }&quot;</span></div><div class="line"><a name="l00020"></a><span class="lineno">   20</span>&#160;    <span class="stringliteral">&quot;{v       |     | Input from video file, if ommited, input comes from camera }&quot;</span></div><div class="line"><a name="l00021"></a><span class="lineno">   21</span>&#160;    <span class="stringliteral">&quot;{ci      | 0   | Camera id if input doesnt come from video (-v) }&quot;</span></div><div class="line"><a name="l00022"></a><span class="lineno">   22</span>&#160;    <span class="stringliteral">&quot;{nc      | 1   | Maximum number of charts in the image }&quot;</span></div><div class="line"><a name="l00023"></a><span class="lineno">   23</span>&#160;    <span class="stringliteral">&quot;{use_gpu |     | Add this flag if you want to use gpu}&quot;</span>};</div><div class="line"><a name="l00024"></a><span class="lineno">   24</span>&#160;</div><div class="line"><a name="l00025"></a><span class="lineno">   25</span>&#160;<span class="keywordtype">int</span> main(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> *argv[])</div><div class="line"><a name="l00026"></a><span class="lineno">   26</span>&#160;{</div><div class="line"><a name="l00027"></a><span class="lineno">   27</span>&#160;    <span class="comment">// ----------------------------------------------------------</span></div><div class="line"><a name="l00028"></a><span class="lineno">   28</span>&#160;    <span class="comment">// Scroll down a bit (~50 lines) to find actual relevant code</span></div><div class="line"><a name="l00029"></a><span class="lineno">   29</span>&#160;    <span class="comment">// ----------------------------------------------------------</span></div><div class="line"><a name="l00030"></a><span class="lineno">   30</span>&#160;</div><div class="line"><a name="l00031"></a><span class="lineno">   31</span>&#160;    <a class="code" href="../../d0/d2e/classcv_1_1CommandLineParser.html">CommandLineParser</a> parser(argc, argv, keys);</div><div class="line"><a name="l00032"></a><span class="lineno">   32</span>&#160;    parser.about(about);</div><div class="line"><a name="l00033"></a><span class="lineno">   33</span>&#160;</div><div class="line"><a name="l00034"></a><span class="lineno">   34</span>&#160;    <span class="keywordflow">if</span> (parser.has(<span class="stringliteral">&quot;help&quot;</span>))</div><div class="line"><a name="l00035"></a><span class="lineno">   35</span>&#160;    {</div><div class="line"><a name="l00036"></a><span class="lineno">   36</span>&#160;        parser.printMessage();</div><div class="line"><a name="l00037"></a><span class="lineno">   37</span>&#160;        <span class="keywordflow">return</span> -1;</div><div class="line"><a name="l00038"></a><span class="lineno">   38</span>&#160;    }</div><div class="line"><a name="l00039"></a><span class="lineno">   39</span>&#160;</div><div class="line"><a name="l00040"></a><span class="lineno">   40</span>&#160;    <span class="keywordtype">int</span> t = parser.get&lt;<span class="keywordtype">int</span>&gt;(<span class="stringliteral">&quot;t&quot;</span>);</div><div class="line"><a name="l00041"></a><span class="lineno">   41</span>&#160;</div><div class="line"><a name="l00042"></a><span class="lineno">   42</span>&#160;    <a class="code" href="../../db/de0/group__core__utils.html#gaf62bcd90f70e275191ab95136d85906b">CV_Assert</a>(0 &lt;= t &amp;&amp; t &lt;= 2);</div><div class="line"><a name="l00043"></a><span class="lineno">   43</span>&#160;    <a class="code" href="../../dd/d19/group__mcc.html#ga836ee96afcefd4f35e95760ca9e8163d">TYPECHART</a> chartType = <a class="code" href="../../dd/d19/group__mcc.html#ga836ee96afcefd4f35e95760ca9e8163d">TYPECHART</a>(t);</div><div class="line"><a name="l00044"></a><span class="lineno">   44</span>&#160;</div><div class="line"><a name="l00045"></a><span class="lineno">   45</span>&#160;    <span class="keywordtype">string</span> model_path = parser.get&lt;<span class="keywordtype">string</span>&gt;(<span class="stringliteral">&quot;m&quot;</span>);</div><div class="line"><a name="l00046"></a><span class="lineno">   46</span>&#160;    <span class="keywordtype">string</span> pbtxt_path = parser.get&lt;<span class="keywordtype">string</span>&gt;(<span class="stringliteral">&quot;pb&quot;</span>);</div><div class="line"><a name="l00047"></a><span class="lineno">   47</span>&#160;</div><div class="line"><a name="l00048"></a><span class="lineno">   48</span>&#160;    <span class="keywordtype">int</span> camId = parser.get&lt;<span class="keywordtype">int</span>&gt;(<span class="stringliteral">&quot;ci&quot;</span>);</div><div class="line"><a name="l00049"></a><span class="lineno">   49</span>&#160;    <span class="keywordtype">int</span> nc = parser.get&lt;<span class="keywordtype">int</span>&gt;(<span class="stringliteral">&quot;nc&quot;</span>);</div><div class="line"><a name="l00050"></a><span class="lineno">   50</span>&#160;</div><div class="line"><a name="l00051"></a><span class="lineno">   51</span>&#160;    <a class="code" href="../../dc/d84/group__core__basic.html#ga1f6634802eeadfd7245bc75cf3e216c2">String</a> video;</div><div class="line"><a name="l00052"></a><span class="lineno">   52</span>&#160;</div><div class="line"><a name="l00053"></a><span class="lineno">   53</span>&#160;    <span class="keywordflow">if</span> (parser.has(<span class="stringliteral">&quot;v&quot;</span>))</div><div class="line"><a name="l00054"></a><span class="lineno">   54</span>&#160;        video = parser.get&lt;<a class="code" href="../../dc/d84/group__core__basic.html#ga1f6634802eeadfd7245bc75cf3e216c2">String</a>&gt;(<span class="stringliteral">&quot;v&quot;</span>);</div><div class="line"><a name="l00055"></a><span class="lineno">   55</span>&#160;</div><div class="line"><a name="l00056"></a><span class="lineno">   56</span>&#160;    <span class="keywordtype">bool</span> use_gpu = parser.has(<span class="stringliteral">&quot;use_gpu&quot;</span>);</div><div class="line"><a name="l00057"></a><span class="lineno">   57</span>&#160;</div><div class="line"><a name="l00058"></a><span class="lineno">   58</span>&#160;    <span class="keywordflow">if</span> (!parser.check())</div><div class="line"><a name="l00059"></a><span class="lineno">   59</span>&#160;    {</div><div class="line"><a name="l00060"></a><span class="lineno">   60</span>&#160;        parser.printErrors();</div><div class="line"><a name="l00061"></a><span class="lineno">   61</span>&#160;        <span class="keywordflow">return</span> 0;</div><div class="line"><a name="l00062"></a><span class="lineno">   62</span>&#160;    }</div><div class="line"><a name="l00063"></a><span class="lineno">   63</span>&#160;</div><div class="line"><a name="l00064"></a><span class="lineno">   64</span>&#160;    <a class="code" href="../../d8/dfe/classcv_1_1VideoCapture.html">VideoCapture</a> inputVideo;</div><div class="line"><a name="l00065"></a><span class="lineno">   65</span>&#160;    <span class="keywordtype">int</span> waitTime;</div><div class="line"><a name="l00066"></a><span class="lineno">   66</span>&#160;    <span class="keywordflow">if</span> (!video.empty())</div><div class="line"><a name="l00067"></a><span class="lineno">   67</span>&#160;    {</div><div class="line"><a name="l00068"></a><span class="lineno">   68</span>&#160;        inputVideo.<a class="code" href="../../d8/dfe/classcv_1_1VideoCapture.html#a614a1702e15f42ede5100014ce7f48ed">open</a>(video);</div><div class="line"><a name="l00069"></a><span class="lineno">   69</span>&#160;        waitTime = 10;</div><div class="line"><a name="l00070"></a><span class="lineno">   70</span>&#160;    }</div><div class="line"><a name="l00071"></a><span class="lineno">   71</span>&#160;    <span class="keywordflow">else</span></div><div class="line"><a name="l00072"></a><span class="lineno">   72</span>&#160;    {</div><div class="line"><a name="l00073"></a><span class="lineno">   73</span>&#160;        inputVideo.<a class="code" href="../../d8/dfe/classcv_1_1VideoCapture.html#a614a1702e15f42ede5100014ce7f48ed">open</a>(camId);</div><div class="line"><a name="l00074"></a><span class="lineno">   74</span>&#160;        waitTime = 10;</div><div class="line"><a name="l00075"></a><span class="lineno">   75</span>&#160;    }</div><div class="line"><a name="l00076"></a><span class="lineno">   76</span>&#160;</div><div class="line"><a name="l00077"></a><span class="lineno">   77</span>&#160;    <span class="comment">//--------------------------------------------------------------------------</span></div><div class="line"><a name="l00078"></a><span class="lineno">   78</span>&#160;    <span class="comment">//-------------------------Actual Relevant Code-----------------------------</span></div><div class="line"><a name="l00079"></a><span class="lineno">   79</span>&#160;    <span class="comment">//--------------------------------------------------------------------------</span></div><div class="line"><a name="l00080"></a><span class="lineno">   80</span>&#160;</div><div class="line"><a name="l00081"></a><span class="lineno">   81</span>&#160;    <span class="comment">//load the network</span></div><div class="line"><a name="l00082"></a><span class="lineno">   82</span>&#160;</div><div class="line"><a name="l00083"></a><span class="lineno">   83</span>&#160;    <a class="code" href="../../db/d30/classcv_1_1dnn_1_1Net.html">cv::dnn::Net</a> net = <a class="code" href="../../d6/d0f/group__dnn.html#gad820b280978d06773234ba6841e77e8d">cv::dnn::readNetFromTensorflow</a>(model_path, pbtxt_path);</div><div class="line"><a name="l00084"></a><span class="lineno">   84</span>&#160;</div><div class="line"><a name="l00085"></a><span class="lineno">   85</span>&#160;    <span class="keywordflow">if</span> (use_gpu)</div><div class="line"><a name="l00086"></a><span class="lineno">   86</span>&#160;    {</div><div class="line"><a name="l00087"></a><span class="lineno">   87</span>&#160;        net.<a class="code" href="../../db/d30/classcv_1_1dnn_1_1Net.html#a7f767df11386d39374db49cd8df8f59e">setPreferableBackend</a>(<a class="code" href="../../d6/d0f/group__dnn.html#gga186f7d9bfacac8b0ff2e26e2eab02625ab242310e1ca6b405ead9308f4b66971c">dnn::DNN_BACKEND_CUDA</a>);</div><div class="line"><a name="l00088"></a><span class="lineno">   88</span>&#160;        net.<a class="code" href="../../db/d30/classcv_1_1dnn_1_1Net.html#a9dddbefbc7f3defbe3eeb5dc3d3483f4">setPreferableTarget</a>(<a class="code" href="../../d6/d0f/group__dnn.html#gga709af7692ba29788182cf573531b0ff5a5d7e050b90e78a923d304c328d16e5f1">dnn::DNN_TARGET_CUDA</a>);</div><div class="line"><a name="l00089"></a><span class="lineno">   89</span>&#160;    }</div><div class="line"><a name="l00090"></a><span class="lineno">   90</span>&#160;</div><div class="line"><a name="l00091"></a><span class="lineno">   91</span>&#160;    <a class="code" href="../../dc/d84/group__core__basic.html#ga6395ca871a678020c4a31fadf7e8cc63">Ptr&lt;CCheckerDetector&gt;</a> detector = CCheckerDetector::create();</div><div class="line"><a name="l00092"></a><span class="lineno">   92</span>&#160;    <span class="keywordflow">if</span> (!detector-&gt;setNet(net))</div><div class="line"><a name="l00093"></a><span class="lineno">   93</span>&#160;    {</div><div class="line"><a name="l00094"></a><span class="lineno">   94</span>&#160;        cout &lt;&lt; <span class="stringliteral">&quot;Loading Model failed: Aborting&quot;</span> &lt;&lt; endl;</div><div class="line"><a name="l00095"></a><span class="lineno">   95</span>&#160;        <span class="keywordflow">return</span> 0;</div><div class="line"><a name="l00096"></a><span class="lineno">   96</span>&#160;    }</div><div class="line"><a name="l00097"></a><span class="lineno">   97</span>&#160;</div><div class="line"><a name="l00098"></a><span class="lineno">   98</span>&#160;    <span class="keywordflow">while</span> (inputVideo.<a class="code" href="../../d8/dfe/classcv_1_1VideoCapture.html#ae38c2a053d39d6b20c9c649e08ff0146">grab</a>())</div><div class="line"><a name="l00099"></a><span class="lineno">   99</span>&#160;    {</div><div class="line"><a name="l00100"></a><span class="lineno">  100</span>&#160;        <a class="code" href="../../d3/d63/classcv_1_1Mat.html">Mat</a> image, imageCopy;</div><div class="line"><a name="l00101"></a><span class="lineno">  101</span>&#160;        inputVideo.<a class="code" href="../../d8/dfe/classcv_1_1VideoCapture.html#a9ac7f4b1cdfe624663478568486e6712">retrieve</a>(image);</div><div class="line"><a name="l00102"></a><span class="lineno">  102</span>&#160;</div><div class="line"><a name="l00103"></a><span class="lineno">  103</span>&#160;        imageCopy = image.<a class="code" href="../../d3/d63/classcv_1_1Mat.html#adff2ea98da45eae0833e73582dd4a660">clone</a>();</div><div class="line"><a name="l00104"></a><span class="lineno">  104</span>&#160;</div><div class="line"><a name="l00105"></a><span class="lineno">  105</span>&#160;        <span class="comment">// Marker type to detect</span></div><div class="line"><a name="l00106"></a><span class="lineno">  106</span>&#160;        <span class="keywordflow">if</span> (!detector-&gt;process(image, chartType, nc, <span class="keyword">true</span>))</div><div class="line"><a name="l00107"></a><span class="lineno">  107</span>&#160;        {</div><div class="line"><a name="l00108"></a><span class="lineno">  108</span>&#160;            printf(<span class="stringliteral">&quot;ChartColor not detected \n&quot;</span>);</div><div class="line"><a name="l00109"></a><span class="lineno">  109</span>&#160;        }</div><div class="line"><a name="l00110"></a><span class="lineno">  110</span>&#160;        <span class="keywordflow">else</span></div><div class="line"><a name="l00111"></a><span class="lineno">  111</span>&#160;        {</div><div class="line"><a name="l00112"></a><span class="lineno">  112</span>&#160;</div><div class="line"><a name="l00113"></a><span class="lineno">  113</span>&#160;            <span class="comment">// get checker</span></div><div class="line"><a name="l00114"></a><span class="lineno">  114</span>&#160;            std::vector&lt;Ptr&lt;mcc::CChecker&gt;&gt; checkers = detector-&gt;getListColorChecker();</div><div class="line"><a name="l00115"></a><span class="lineno">  115</span>&#160;            <span class="keywordflow">for</span> (<a class="code" href="../../dc/d84/group__core__basic.html#ga6395ca871a678020c4a31fadf7e8cc63">Ptr&lt;mcc::CChecker&gt;</a> checker : checkers)</div><div class="line"><a name="l00116"></a><span class="lineno">  116</span>&#160;            {</div><div class="line"><a name="l00117"></a><span class="lineno">  117</span>&#160;                <span class="comment">// current checker</span></div><div class="line"><a name="l00118"></a><span class="lineno">  118</span>&#160;</div><div class="line"><a name="l00119"></a><span class="lineno">  119</span>&#160;                <a class="code" href="../../dc/d84/group__core__basic.html#ga6395ca871a678020c4a31fadf7e8cc63">Ptr&lt;CCheckerDraw&gt;</a> cdraw = CCheckerDraw::create(checker);</div><div class="line"><a name="l00120"></a><span class="lineno">  120</span>&#160;                cdraw-&gt;draw(image);</div><div class="line"><a name="l00121"></a><span class="lineno">  121</span>&#160;            }</div><div class="line"><a name="l00122"></a><span class="lineno">  122</span>&#160;        }</div><div class="line"><a name="l00123"></a><span class="lineno">  123</span>&#160;</div><div class="line"><a name="l00124"></a><span class="lineno">  124</span>&#160;        <a class="code" href="../../d7/dfc/group__highgui.html#ga453d42fe4cb60e5723281a89973ee563">imshow</a>(<span class="stringliteral">&quot;image result | q or esc to quit&quot;</span>, image);</div><div class="line"><a name="l00125"></a><span class="lineno">  125</span>&#160;        <a class="code" href="../../d7/dfc/group__highgui.html#ga453d42fe4cb60e5723281a89973ee563">imshow</a>(<span class="stringliteral">&quot;original&quot;</span>, imageCopy);</div><div class="line"><a name="l00126"></a><span class="lineno">  126</span>&#160;        <span class="keywordtype">char</span> key = (char)<a class="code" href="../../d7/dfc/group__highgui.html#ga5628525ad33f52eab17feebcfba38bd7">waitKey</a>(waitTime);</div><div class="line"><a name="l00127"></a><span class="lineno">  127</span>&#160;        <span class="keywordflow">if</span> (key == 27)</div><div class="line"><a name="l00128"></a><span class="lineno">  128</span>&#160;            <span class="keywordflow">break</span>;</div><div class="line"><a name="l00129"></a><span class="lineno">  129</span>&#160;    }</div><div class="line"><a name="l00130"></a><span class="lineno">  130</span>&#160;</div><div class="line"><a name="l00131"></a><span class="lineno">  131</span>&#160;    <span class="keywordflow">return</span> 0;</div><div class="line"><a name="l00132"></a><span class="lineno">  132</span>&#160;}</div><div class="ttc" id="group__dnn_html_gga186f7d9bfacac8b0ff2e26e2eab02625ab242310e1ca6b405ead9308f4b66971c"><div class="ttname"><a href="../../d6/d0f/group__dnn.html#gga186f7d9bfacac8b0ff2e26e2eab02625ab242310e1ca6b405ead9308f4b66971c">cv::dnn::DNN_BACKEND_CUDA</a></div><div class="ttdef"><b>Definition:</b> dnn.hpp:76</div></div>
<div class="ttc" id="group__core__basic_html_ga6395ca871a678020c4a31fadf7e8cc63"><div class="ttname"><a href="../../dc/d84/group__core__basic.html#ga6395ca871a678020c4a31fadf7e8cc63">cv::Ptr</a></div><div class="ttdeci">std::shared_ptr&lt; _Tp &gt; Ptr</div><div class="ttdef"><b>Definition:</b> cvstd_wrapper.hpp:23</div></div>
<div class="ttc" id="classcv_1_1dnn_1_1Net_html_a7f767df11386d39374db49cd8df8f59e"><div class="ttname"><a href="../../db/d30/classcv_1_1dnn_1_1Net.html#a7f767df11386d39374db49cd8df8f59e">cv::dnn::Net::setPreferableBackend</a></div><div class="ttdeci">void setPreferableBackend(int backendId)</div><div class="ttdoc">Ask network to use specific computation backend where it supported. </div></div>
<div class="ttc" id="classcv_1_1dnn_1_1Net_html_a9dddbefbc7f3defbe3eeb5dc3d3483f4"><div class="ttname"><a href="../../db/d30/classcv_1_1dnn_1_1Net.html#a9dddbefbc7f3defbe3eeb5dc3d3483f4">cv::dnn::Net::setPreferableTarget</a></div><div class="ttdeci">void setPreferableTarget(int targetId)</div><div class="ttdoc">Ask network to make computations on specific target device. </div></div>
<div class="ttc" id="highgui_8hpp_html"><div class="ttname"><a href="../../d4/dd5/highgui_8hpp.html">highgui.hpp</a></div></div>
<div class="ttc" id="group__highgui_html_ga453d42fe4cb60e5723281a89973ee563"><div class="ttname"><a href="../../d7/dfc/group__highgui.html#ga453d42fe4cb60e5723281a89973ee563">cv::imshow</a></div><div class="ttdeci">void imshow(const String &amp;winname, InputArray mat)</div><div class="ttdoc">Displays an image in the specified window. </div></div>
<div class="ttc" id="classcv_1_1dnn_1_1Net_html"><div class="ttname"><a href="../../db/d30/classcv_1_1dnn_1_1Net.html">cv::dnn::Net</a></div><div class="ttdoc">This class allows to create and manipulate comprehensive artificial neural networks. </div><div class="ttdef"><b>Definition:</b> dnn.hpp:406</div></div>
<div class="ttc" id="namespacecv_html"><div class="ttname"><a href="../../d2/d75/namespacecv.html">cv</a></div><div class="ttdoc">&quot;black box&quot; representation of the file storage associated with a file on disk. </div><div class="ttdef"><b>Definition:</b> affine.hpp:51</div></div>
<div class="ttc" id="classcv_1_1CommandLineParser_html"><div class="ttname"><a href="../../d0/d2e/classcv_1_1CommandLineParser.html">cv::CommandLineParser</a></div><div class="ttdoc">Designed for command line parsing. </div><div class="ttdef"><b>Definition:</b> utility.hpp:799</div></div>
<div class="ttc" id="group__core__utils_html_gaf62bcd90f70e275191ab95136d85906b"><div class="ttname"><a href="../../db/de0/group__core__utils.html#gaf62bcd90f70e275191ab95136d85906b">CV_Assert</a></div><div class="ttdeci">#define CV_Assert(expr)</div><div class="ttdoc">Checks a condition at runtime and throws exception if it fails. </div><div class="ttdef"><b>Definition:</b> base.hpp:342</div></div>
<div class="ttc" id="classcv_1_1VideoCapture_html"><div class="ttname"><a href="../../d8/dfe/classcv_1_1VideoCapture.html">cv::VideoCapture</a></div><div class="ttdoc">Class for video capturing from video files, image sequences or cameras. </div><div class="ttdef"><b>Definition:</b> videoio.hpp:664</div></div>
<div class="ttc" id="group__mcc_html_ga836ee96afcefd4f35e95760ca9e8163d"><div class="ttname"><a href="../../dd/d19/group__mcc.html#ga836ee96afcefd4f35e95760ca9e8163d">cv::mcc::TYPECHART</a></div><div class="ttdeci">TYPECHART</div><div class="ttdoc">enum to hold the type of the checker </div><div class="ttdef"><b>Definition:</b> checker_model.hpp:46</div></div>
<div class="ttc" id="dnn_8hpp_html"><div class="ttname"><a href="../../d9/d8c/dnn_8hpp.html">dnn.hpp</a></div></div>
<div class="ttc" id="mcc_8hpp_html"><div class="ttname"><a href="../../df/d35/mcc_8hpp.html">mcc.hpp</a></div></div>
<div class="ttc" id="group__dnn_html_gad820b280978d06773234ba6841e77e8d"><div class="ttname"><a href="../../d6/d0f/group__dnn.html#gad820b280978d06773234ba6841e77e8d">cv::dnn::readNetFromTensorflow</a></div><div class="ttdeci">Net readNetFromTensorflow(const String &amp;model, const String &amp;config=String())</div><div class="ttdoc">Reads a network model stored in TensorFlow framework&amp;#39;s format. </div></div>
<div class="ttc" id="classcv_1_1VideoCapture_html_a9ac7f4b1cdfe624663478568486e6712"><div class="ttname"><a href="../../d8/dfe/classcv_1_1VideoCapture.html#a9ac7f4b1cdfe624663478568486e6712">cv::VideoCapture::retrieve</a></div><div class="ttdeci">virtual bool retrieve(OutputArray image, int flag=0)</div><div class="ttdoc">Decodes and returns the grabbed video frame. </div></div>
<div class="ttc" id="core_2include_2opencv2_2core_8hpp_html"><div class="ttname"><a href="../../d0/d9c/core_2include_2opencv2_2core_8hpp.html">core.hpp</a></div></div>
<div class="ttc" id="classcv_1_1VideoCapture_html_a614a1702e15f42ede5100014ce7f48ed"><div class="ttname"><a href="../../d8/dfe/classcv_1_1VideoCapture.html#a614a1702e15f42ede5100014ce7f48ed">cv::VideoCapture::open</a></div><div class="ttdeci">virtual bool open(const String &amp;filename, int apiPreference=CAP_ANY)</div><div class="ttdoc">Opens a video file or a capturing device or an IP video stream for video capturing. </div></div>
<div class="ttc" id="classcv_1_1VideoCapture_html_ae38c2a053d39d6b20c9c649e08ff0146"><div class="ttname"><a href="../../d8/dfe/classcv_1_1VideoCapture.html#ae38c2a053d39d6b20c9c649e08ff0146">cv::VideoCapture::grab</a></div><div class="ttdeci">virtual bool grab()</div><div class="ttdoc">Grabs the next frame from video file or capturing device. </div></div>
<div class="ttc" id="group__core__basic_html_ga1f6634802eeadfd7245bc75cf3e216c2"><div class="ttname"><a href="../../dc/d84/group__core__basic.html#ga1f6634802eeadfd7245bc75cf3e216c2">cv::String</a></div><div class="ttdeci">std::string String</div><div class="ttdef"><b>Definition:</b> cvstd.hpp:150</div></div>
<div class="ttc" id="group__dnn_html_gga709af7692ba29788182cf573531b0ff5a5d7e050b90e78a923d304c328d16e5f1"><div class="ttname"><a href="../../d6/d0f/group__dnn.html#gga709af7692ba29788182cf573531b0ff5a5d7e050b90e78a923d304c328d16e5f1">cv::dnn::DNN_TARGET_CUDA</a></div><div class="ttdef"><b>Definition:</b> dnn.hpp:95</div></div>
<div class="ttc" id="classcv_1_1Mat_html_adff2ea98da45eae0833e73582dd4a660"><div class="ttname"><a href="../../d3/d63/classcv_1_1Mat.html#adff2ea98da45eae0833e73582dd4a660">cv::Mat::clone</a></div><div class="ttdeci">Mat clone() const CV_NODISCARD</div><div class="ttdoc">Creates a full copy of the array and the underlying data. </div></div>
<div class="ttc" id="classcv_1_1Mat_html"><div class="ttname"><a href="../../d3/d63/classcv_1_1Mat.html">cv::Mat</a></div><div class="ttdoc">n-dimensional dense array class </div><div class="ttdef"><b>Definition:</b> mat.hpp:801</div></div>
<div class="ttc" id="group__highgui_html_ga5628525ad33f52eab17feebcfba38bd7"><div class="ttname"><a href="../../d7/dfc/group__highgui.html#ga5628525ad33f52eab17feebcfba38bd7">cv::waitKey</a></div><div class="ttdeci">int waitKey(int delay=0)</div><div class="ttdoc">Waits for a pressed key. </div></div>
</div><!-- fragment --><h2>Explanation </h2>
<ol type="1">
<li><p class="startli"><b>Set header and namespaces</b> </p><div class="fragment"><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="../../df/d35/mcc_8hpp.html">opencv2/mcc.hpp</a>&gt;</span></div><div class="line"><span class="keyword">using namespace </span>std;</div><div class="line"><span class="keyword">using namespace </span><a class="code" href="../../d2/d75/namespacecv.html">cv</a>;</div><div class="line"><span class="keyword">using namespace </span>mcc;</div></div><!-- fragment --><p class="startli">If you want you can set the namespace like the code above.</p>
</li>
<li><p class="startli"><b>Create the detector object</b> </p><div class="fragment"><div class="line">Ptr&lt;CCheckerDetector&gt; detector = CCheckerDetector::create();</div></div><!-- fragment --><p class="startli">This is just to create the object.</p>
</li>
<li><p class="startli"><b>Load the model</b> </p><div class="fragment"><div class="line"><a class="code" href="../../db/d30/classcv_1_1dnn_1_1Net.html">cv::dnn::Net</a> net = <a class="code" href="../../d6/d0f/group__dnn.html#gad820b280978d06773234ba6841e77e8d">cv::dnn::readNetFromTensorflow</a>(model_path, pbtxt_path);</div></div><!-- fragment --><p class="startli">Load the model, here the model supplied with model was trained in tensorflow so we are loading it in tensorflow, but if you have some other model trained in some other framework you can use that also.</p>
</li>
<li><p class="startli">**(Optional) Set the dnn backend to CUDA** </p><div class="fragment"><div class="line">net.<a class="code" href="../../db/d30/classcv_1_1dnn_1_1Net.html#a7f767df11386d39374db49cd8df8f59e">setPreferableBackend</a>(<a class="code" href="../../d6/d0f/group__dnn.html#gga186f7d9bfacac8b0ff2e26e2eab02625ab242310e1ca6b405ead9308f4b66971c">dnn::DNN_BACKEND_CUDA</a>);</div><div class="line">net.<a class="code" href="../../db/d30/classcv_1_1dnn_1_1Net.html#a9dddbefbc7f3defbe3eeb5dc3d3483f4">setPreferableTarget</a>(<a class="code" href="../../d6/d0f/group__dnn.html#gga709af7692ba29788182cf573531b0ff5a5d7e050b90e78a923d304c328d16e5f1">dnn::DNN_TARGET_CUDA</a>);</div></div><!-- fragment --><p class="startli">Models run much faster on CUDA, so use CUDA if possible.</p>
</li>
<li><p class="startli"><b>Run the detector</b> </p><div class="fragment"><div class="line">detector-&gt;process(image, chartType, max_number_charts_in_image, <span class="keyword">true</span>);</div></div><!-- fragment --><p class="startli">If the detector successfully detects atleast one chart, it return true otherwise it returns false. In the above given code we print a failure message if no chart were detected. Otherwise if it were successful, the list of colorcharts is stored inside the detector itself, we will see in the next step on how to extract it. The fourth parameter is for deciding whether to use the net or not.</p>
</li>
<li><p class="startli"><b>Get List of ColorCheckers</b> </p><div class="fragment"><div class="line">std::vector&lt;cv::Ptr&lt;mcc::CChecker&gt;&gt; checkers;</div><div class="line">detector-&gt;getListColorChecker(checkers);</div></div><!-- fragment --><p class="startli">All the colorcheckers that were detected are now stored in the 'checkers' vector.</p>
</li>
<li><p class="startli"><b>Draw the colorcheckers back to the image</b> </p><div class="fragment"><div class="line"><span class="keywordflow">for</span>(Ptr&lt;mcc::CChecker&gt; checker : checkers)</div><div class="line">{</div><div class="line">    <span class="comment">// current checker</span></div><div class="line">    Ptr&lt;CCheckerDraw&gt; cdraw = CCheckerDraw::create(checker);</div><div class="line">    cdraw-&gt;draw(image);</div><div class="line">}</div></div><!-- fragment --><p class="startli">Loop through all the checkers one by one and then draw them. </p>
</li>
</ol>
</div></div><!-- contents -->
<!-- HTML footer for doxygen 1.8.6-->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated on Fri Apr 2 2021 11:36:39 for OpenCV by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="../../doxygen.png" alt="doxygen"/>
</a> 1.8.13
</small></address>
<script type="text/javascript">
//<![CDATA[
addTutorialsButtons();
//]]>
</script>
</body>
</html>
